import seaborn as sns
import pandas as pd
import numpy as np
import plotly.express as px
%pylab inline
import sklearn as sk
import sklearn.tree as tree
from IPython.display import Image
import pydotplus
import us
from sklearn.datasets import load_iris
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import warnings
warnings.filterwarnings("ignore")
df=pd.read_csv('nhtsa_survey_data.csv')
pd.set_option('display.max_columns', 10)
pd.set_option('display.max_rows', 10)
df.rename(columns={'Unnamed: 0':'Index','number_of_vehicle_forms_submitted_all':'Total_vehicle_forms',\
'number_of_motor_vehicles_in_transport_mvit':'MV_transport',\
'number_of_parked_working_vehicles':'Parked_vehicles',\
'number_of_forms_submitted_for_persons_not_in_motor_vehicles':'Total_Persons_notin_MV',\
'number_of_persons_not_in_motor_vehicles_in_transport_mvit':'Total_Persons_notin_MVIT',\
'number_of_persons_in_motor_vehicles_in_transport_mvit':'Total_Persons_in_MVIT',\
'number_of_forms_submitted_for_persons_in_motor_vehicles':'Total_Persons_in_MV'}, inplace=True)
df.set_index('Index', inplace=True)
df.replace({'day_of_week':{1:'Sunday',2:'Monday',\
3:'Tuesday',4:'Wednesday',\
5:'Thursday',6:'Friday',7:'Saturday'}}, inplace=True)
df.replace({'month_of_crash':{1:'Jan',2:'Feb',3:'Mar',\
4:'Apr',5:'May',6:'June',\
7:'July',8:'Aug',9:'Sep',\
10:'Oct',11:'Nov',12:'Dec'}}, inplace=True)
df.drop(columns=["atmospheric_conditions_2_name", "atmospheric_conditions_name"], inplace=True)
list_col = df.iloc[:,19:36].columns.tolist()
list_col = ["route_name", "trafficway", "latitude", "longitude",\
"special_juris", "first_crash_event", "Manner_collision",\
"interchange_area", "junction_location","intersection_type", \
"work_zone", "relation_trafficway", "light_condition",\
"atmospheric_conditions", "School_bus_rel", "crash_factors",\
"fatalities_num"]
df_ren = df.columns.tolist()
df_ren[19:36] = list_col
df.columns = df_ren
df.replace({'first_crash_event':{'Rollover/Overturn':'Rollover',\
'Fire/Explosion':'Explosion',\
'Immersion (or Partial Immersion, Since 2012)':'Immersion',\
'Fell/Jumped from Vehicle':'fell_out',\
'Injured in Vehicle (Non-Collision)':'Injured_Non_Col',\
'Other Non-Collision':'Other_Non_col',\
'Motor Vehicle in Transport':'MV_transport',\
'Parked Motor Vehicle (Not In Transport)':'Parked_Vehicle',\
'Other Object (Not Fixed)':'Object_NFix',\
'Impact Attenuator/Crash Cushion':'Crash_Cushion',\
'Bridge Pier or Support':'Bridge_pier',\
'Bridge Rail (Includes Parapet)':'Bridge_railling',\
'Concrete Traffic Barrier':'Traffic_barrier',\
'Other Traffic Barrier':'Traffic_barrier',\
'Traffic Sign Support':'Traffic_barrier',\
'Utility Pole/Light Support':'Pole',\
'Other Post, Other Pole, or Other Support':'Pole',\
'Tree (Standing Only)':'Tree','Other Fixed Object':'Fixed_obj',\
'Pavement Surface Irregularity (Ruts, Potholes, Grates, etc.)':'Pavement_issue',\
'Working Motor Vehicle':'Working_MV','Guardrail Face':'Gaurdrail',\
'Guardrail End':'Gaurdrail',\
'Jackknife (Harmful to This Vehicle)':'Jacknife',\
'Motor Vehicle In-Transport Strikes or is Struck by Cargo':'MV_Moving',\
'Persons or\nObjects Set-in-Motion from/by Another Motor Vehicle In-Transport':\
'MV_Moving','Cable Barrier (Since 2008)':'Cable_barrier',\
'Cargo/Equipment Loss or Shift (Harmful to This Vehicle)':'Cargo_loss',\
'Object Fell From Motor Vehicle In-Transport (Since 2013)':'Obj_Fell',\
'Thrown or Falling Object':'Obj_Fell',\
'Ridden Animal or Animal-Drawn Conveyance (Since 1998)':'Animal_Ridding',\
'Non-Motorist on Personal Conveyance':'NM_Conveyance'}}, inplace=True)
df.Manner_collision.\
replace(to_replace="Not Collision with Motor Vehicle in Transport (Not Necessarily in Transport for\n2005-2009)",\
value="No_collision_MV", inplace=True)
df.rename(columns={'died_at_scene_en_route': 'death'},inplace=True)
df.rename(columns={ 'police_reported_drug_involvement':'drug',\
'police_reported_alcohol_involvement':'alcohol',\
'air_bag_deployed_name':'airbag',\
'indication_of_misuse_of_restraint_system_helmet':'misuse_restraint',\
'restraint_system_helmet_use_name':'restraint',\
'number_of_fatalities':'fatalities_num',
'number_of_drunk_drivers': 'drunk_drivers_num',
'driver_distracted_by_name': 'driver_distracted',
'driver_maneuvered_to_avoid_name': 'driver_maneuvered',
'injury_severity_name': 'injury_severity',
'person_type_name': 'person_type',
'violations_charged_name': 'violations'}, inplace = True)
df.replace({'death':{'Died at Scene':'At Scene',\
'Died En Route':'En Route',\
'Not Applicable':'No'}}, inplace=True)
df.replace({'drug':{'Unknown (Police Reported)':'Unknown',\
'No (Drugs Not Involved)':'No',\
'Yes (Drugs Involved)':'Yes'}}, inplace=True)
df.replace({'alcohol':{'Unknown (Police Reported)':'Unknown',\
'No (Alcohol Not Involved)':'No',\
'Yes (Alcohol Involved)':'Yes'}}, inplace=True)
df.replace({'airbag':{'Not Deployed':'No',\
'Deployment Unknown':'Unknown'}},inplace=True)
df['air_bag'] = df.airbag.apply(lambda x: 'Deployed' if 'Deployed:' in x else x)
df.air_bag.replace(to_replace='No',value='Not Deployed', inplace=True)
df.drop(['airbag'], axis=1,inplace=True)
df.replace({'restraint':{'None Used':'None',\
'Unknown if Helmet Worn':'Unknown'}}, inplace=True)
df['maneuvered'] = df.driver_maneuvered.apply(lambda x: 'Motor Vehicle' if 'Motor Vehicle' in x else x)
df.drop(['driver_maneuvered'], axis=1, inplace=True)
df.replace({'injury_severity':{'Fatal Injury (K)':'Death',\
'Suspected Serious Injury (A)':'Suspected Serious',
'Suspected Minor Injury (B)':'Suspected Minor',
'Injured, Severity Unknown (U) (Since 1978)':'Injured, Severity Unknown',
'Possible Injury (C)':'Possible Injury',
'No Apparent Injury (O)':'No Apparent Injury'}},inplace=True)
df["violation_reduce"] = df.violations.\
apply(lambda x: "RECKLESS/CARELESS/HIT-AND-RUN" if "RECKLESS/CARELESS/HIT-AND-RUN" in x\
else "IMPAIRMENT OFFENSES" if "IMPAIRMENT OFFENSES" in x\
else "RULES OF THE ROAD" if "RULES OF THE ROAD" in x\
else "NON-MOVING_LICENSE" if "LICENSE" in x\
else "SPEEDING" if "SPEED-RELATED" in x\
else "EQUIPMENT" if "EQUIPMENT" in x else "None")
df.replace({'Manner_collision':{'No_collision_MV':'Single_vehicle','Angle':'Multi_vehicle',\
'Front-to-Front':'Multi_vehicle',\
'Front-to-Rear':'Multi_vehicle','Sideswipe – Same Direction':'Multi_vehicle',\
'Sideswipe – Opposite Direction':'Multi_vehicle' ,\
'Other (End-Swipes and Others)':'Multi_vehicle',\
'Rear-to-Side':'Multi_vehicle','Rear-to-Rear':'Multi_vehicle', \
'Not Reported':'Unknown'}}, inplace=True)
df.replace({'injury_severity':{'No Apparent Injury':'Not_injured','Suspected Minor':'Injured',\
'Suspected Serious':'Injured','Possible Injury':'Injured','Injured, Severity Unknown':'Injured',\
'Died Prior to Crash':'Death'}}, inplace=True)
df.replace({'restraint':{'No Helmet':'None', 'Not Reported':'Unknown'}}, inplace=True)
df['restraint_binary']=df.restraint.apply(lambda x : "Restraint Used" if 'Belt' in x or 'Restraint' in x\
or 'Helmet' in x or 'Other' in x \
else 'Unknown' if 'Unknown' in x \
else "Restraint not used")
df.replace({'air_bag':{'Switched Off':'Not Deployed', \
'Not Reported':'Unknown', \
'Not Applicable':'Deployed'}}, inplace=True)
df.replace({'first_crash_event':{'MV_transport':'Collision_with_moving_obj',\
'Pedestrian':'Collision_with_moving_obj', \
'Rollover':'Non_collision','Tree':'Collision_with_fix_obj',\
'Curb':'Collision_with_fix_obj', \
'Gaurdrail':'Collision_with_fix_obj','Embankment':'Collision_with_fix_obj', \
'Ditch':'Collision_with_fix_obj','Pole':'Collision_with_fix_obj',\
'Traffic_barrier':'Collision_with_fix_obj',
'Pedalcyclist':'Collision_with_moving_obj','Culvert':'Collision_with_fix_obj',\
'Parked_Vehicle':'Collision_with_moving_obj', \
'Fence':'Collision_with_fix_obj','fell_out':'Non_collision',\
'Mail Box':'Collision_with_fix_obj', \
'Fixed_obj':'Collision_with_fix_obj','Live Animal':'Collision_with_moving_obj',\
'Object_NFix':'Collision_with_moving_obj', \
'NM_Conveyance':'Collision_with_moving_obj','Bridge_railling':'Collision_with_fix_obj',\
'Cable_barrier':'Collision_with_fix_obj', \
'Bridge_pier':'Collision_with_fix_obj','Railway Vehicle':'Collision_with_moving_obj',\
'Wall':'Collision_with_fix_obj', \
'Ground':'Collision_with_fix_obj','Boulder':'Collision_with_fix_obj',\
'Crash_Cushion':'Collision_with_fix_obj', \
'Immersion':'Non_collision','Traffic Signal Support':'Collision_with_fix_obj',\
'Building':'Collision_with_fix_obj', \
'MV_Moving':'Collision_with_moving_obj','Shrubbery':'Collision_with_fix_obj',\
'Other_Non_col':'Non_collision', \
'Cargo_loss':'Non_collision','Pavement_issue':'Collision_with_fix_obj',\
'Fire Hydrant':'Collision_with_fix_obj', \
'Obj_Fell':'Collision_with_moving_obj','Snow Bank':'Collision_with_fix_obj',\
'Jacknife':'Non_collision', \
'Working_MV':'Collision_with_moving_obj','Animal_Ridding':'Collision_with_moving_obj', \
'Bridge Overhead Structure':'Collision_with_fix_obj','Injured_Non_Col':'Non_collision', \
'Explosion':'Non_collision'}},inplace=True)
df.drop(columns=['Total_vehicle_forms','MV_transport', 'Parked_vehicles','Total_Persons_in_MV', \
'Total_Persons_notin_MV','Total_Persons_notin_MVIT','Total_Persons_in_MVIT',\
'special_juris'], inplace=True)
df.drop(columns=['functional_system_name','ownership_name','route_name','trafficway',\
'interchange_area','junction_location',\
'intersection_type','work_zone','relation_trafficway',\
'School_bus_rel','crash_factors','timestamp_of_crash','driver_distracted',\
'person_number','person_type','misuse_restraint','maneuvered',\
'county','city',\
'violations','day_of_crash','month_of_crash','restraint','vehicle_number'], inplace=True)
df.head()
df.shape
This dataset contains information on traffic accidents and fatalities collected from the Fatality Analysis Reporting System (FARS) and National Highway Traffic Safety Administration (NHTSA). It reports fatal crashes in 51 states of US in 2016. The cleaned dataset has 23 columns and 84579 rows.
df_vio = df[df.violation_reduce != 'None']
df_vio.groupby('violation_reduce')['violation_reduce'].size().sort_values(ascending=False)
sns.countplot(y='violation_reduce', data=df_vio)
df_vio.groupby('violation_reduce')['fatalities_num'].mean().sort_values(ascending=False)
sns.catplot(x='fatalities_num', data=df_vio, y='violation_reduce', aspect=2, kind='bar')
df_land= df_vio[(df.land_use_name == 'Rural') | (df.land_use_name == 'Urban')]
sns.catplot(x='fatalities_num',y='violation_reduce',hue='land_use_name', data=df_land,kind='bar',aspect=3)
speed_df = df[(df.violation_reduce == 'SPEEDING')]
vio_land_df = df[(df.violation_reduce == 'SPEEDING') & (df.land_use_name == 'Rural')]
vio_land_df.groupby('national_highway_system')['fatalities_num'].count().sort_values(ascending=False)
sns.catplot(x='violation_reduce',hue='national_highway_system', \
data=vio_land_df,kind='count',aspect=2)
df.rename(columns={'light_condition': 'light_condition1'},inplace=True)
df['light_condition'] = df.light_condition1.apply(lambda x: "Dark" if "Dark" in x else x)
df_light = df[((df.light_condition == 'Dark') | (df.light_condition == 'Daylight')|(df.light_condition == 'Dusk')|\
(df.light_condition == 'Dawn')) & (df.violation_reduce != 'None') ]
df.drop(['light_condition1'], axis=1, inplace=True)
sns.catplot(x='violation_reduce', y='fatalities_num',hue='light_condition', \
data=df_light, kind='bar',aspect=2).set_xticklabels(rotation=90)
df.rename(columns={'atmospheric_conditions': 'atmospheric_conditions1'},inplace=True)
df['atmospheric_conditions'] = df.atmospheric_conditions1.\
apply(lambda x: "Snow" if "Snow" in x\
else "Rain" if "Rain" in x\
else x)
df_atom = df[((df.atmospheric_conditions != 'Unknown') & (df.atmospheric_conditions != 'Not Reported')) & \
(df.violation_reduce != 'None')]
df.drop(['atmospheric_conditions1'], axis=1, inplace=True)
sns.catplot(x='violation_reduce', y='fatalities_num',hue='atmospheric_conditions', \
data=df_atom,kind='bar',aspect=3)
speed_sort = speed_df.groupby('state_name')['fatalities_num'].mean().sort_values(ascending=False).reset_index()
speed_sort['state_name_abbr']=speed_sort.state_name.apply(lambda x:us.states.lookup(x).abbr)
fig = px.choropleth(speed_sort,
locations="state_name_abbr",
locationmode='USA-states',
color="fatalities_num",
hover_name="state_name",
scope='usa',
title='Average fatality number caused by speeding in different states',
width=800,
height=400,
color_continuous_scale=px.colors.sequential.Tealgrn)
fig.show()
Speeding causes the highest average fatality among all violations. The fatality rate due to speeding in rural area on national highway system, under daylight and in rainy days are way higher than other land use, light condition and atomospheric condition.
Since Texas and Missisippi are states that cause the highest average fatality number by speeding, it is suggested that the state government to strictly enforcement all cars to install weather-proof tires and install more speed meters in in rural area on national highway system.
df_QT = df.loc[:,['state_name', 'consecutive_number','day_of_week', 'hour_of_crash',\
'drunk_drivers_num', 'age','alcohol', 'drug', 'fatalities_num','death']]
df_QT["death_bin"] = df_QT.death.apply(lambda x: 1 if 'At Scene' in x\
else 1 if 'En Route' in x else 0)
df_QT["alcohol_bin"] = df_QT.alcohol=="Yes"
df_QT["drug_bin"] = df_QT.drug=="Yes"
df_QT["Age_bin1"] = pd.cut(df_QT.age, bins=[0,28,45,65,85,120])
df_QT["Hours_bin"] = pd.cut(df_QT.hour_of_crash, bins=[0,6,12,18,24])
sns.countplot(x = "alcohol_bin", data=df_QT).\
set(xlabel = "Alcohol Consumption", ylabel = "Accidents",\
title = "Distribution of Accicents by Alcohol Consumption")
df_QT.groupby("alcohol_bin").agg({"fatalities_num":"sum","death_bin":"mean"}).\
rename(columns={ "fatalities_num": "Injured People","death_bin":"Average_death"})
sns.regplot(x="alcohol_bin", y= "death_bin", data = df_QT).\
set(xlabel = "Alcohol Consumption", ylabel = "Death", title = "Effect of alcohol over death rate")
sns.catplot(x = "Age_bin1", kind = "count", \
data=df_QT[df_QT.alcohol == "Yes"], aspect=2 ).\
set(xlabel = "Age Group", ylabel = "Accidents")
sns.catplot(x = "alcohol_bin",hue = "Hours_bin",
kind = "count", \
data=df_QT[df_QT.alcohol == "Yes"], aspect=2 ).\
set(xlabel = "Hours bin", ylabel = "Accidents count")
df_QT['weekend']=df['day_of_week'].apply(lambda x: 1 if x=='Saturday' else 1 if x=='Sunday' else 0 )
sns.catplot(x = "alcohol_bin",hue = "Hours_bin", col="weekend",
kind = "count", \
data=df_QT[df_QT.alcohol == "Yes"], aspect=2 ).\
set(xlabel = "Hours bin", ylabel = "Accidents count")
df_QT.groupby(["drug_bin"])["death_bin"].mean()
sns.countplot(x = "drug_bin", data=df_QT).\
set(xlabel = "Drug Consumption", ylabel = "Accidents",\
title = "Distribution of Accicents by Drug Consumption")
sns.regplot(x="drug_bin", y= "death_bin", data = df_QT).\
set(xlabel = "Drug Consumption", ylabel = "Death", title = "Effect of drug over death rate")
sns.catplot(x = "Age_bin1", kind = "count", data=df_QT[df_QT.drug_bin==1]).\
set(xlabel = "Age Group", ylabel = "Accidents")
sns.catplot(x = "drug_bin",hue = "Hours_bin",
kind = "count", \
data=df_QT[df_QT.drug == "Yes"], aspect=2 ).\
set(xlabel = "Hours bin", ylabel = "Accidents count")
sns.catplot(x = "drug_bin",hue = "Hours_bin", col="weekend",
kind = "count", \
data=df_QT[df_QT.drug == "Yes"], aspect=2 ).\
set(xlabel = "Hours bin", ylabel = "Accidents count")
df_QT.groupby(["alcohol_bin", "drug_bin"])["death_bin"].mean()
df_pct=df[(df.Manner_collision!='Unknown') &\
(df.first_crash_event!='Unknown') & (df.air_bag!='Unknown') &\
(df.injury_severity!='Unknown') & (df.restraint_binary!='Unknown') & \
((df.violation_reduce=='SPEEDING') | (df.violation_reduce=='IMPAIRMENT OFFENSES')) & \
(df.atmospheric_conditions=='Clear')]
fr_df=df_pct.groupby('Manner_collision')['injury_severity'].value_counts().unstack()
fr_df.fillna(value=0,inplace=True)
fr_df
ax=fr_df.plot(kind="barh", title='Distribution of injury severity on different manner of collision')
ax.set_xlabel('count')
fr_df2=df_pct.groupby(['Manner_collision','first_crash_event'])['injury_severity'].value_counts().unstack()
fr_df2.fillna(value=0, inplace=True)
fr_df2
ax=fr_df2.plot(kind='barh', \
title='Distribution of injury severity on different manner of collision and the crash events')
ax.set_xlabel('count')
df_pct_air_bag=df_pct[(df_pct.Manner_collision=='Single_vehicle') ]
fr_df3=df_pct_air_bag.groupby('air_bag')['injury_severity'].value_counts().unstack()
fr_df3.fillna(value=0, inplace=True)
fr_df3
ax=fr_df3.plot(kind='bar', title='Distribution of injury severity on Air Bags',\
rot='horizontal')
ax.set_ylabel('count')
fr_df6=df_pct_air_bag.groupby(['air_bag','restraint_binary'])['injury_severity'].value_counts().unstack()
fr_df6.fillna(value=0, inplace=True)
fr_df6
ax=fr_df6.plot(kind='barh', title='Distribution of injury severity on restraints and air bags')
ax.set_xlabel('count')
df_pct_air_bag['Injured'] = df_pct_air_bag.injury_severity.apply(lambda x: \
1 if x=='Death' \
else 0.5 if x=='Injured' else 0 )
df_pct_air_bag['restraint_used'] = df_pct_air_bag.restraint_binary.apply(lambda x: \
1 if x=='Restraint Used'\
else 0 )
df_pct_air_bag['air_bag_deployed'] = df_pct_air_bag.air_bag.apply(lambda x: 1 if x=='Deployed' else 0 )
df_ml3 = df_pct_air_bag.loc[:,["Injured",'restraint_binary','air_bag','Manner_collision']]
df_ml3_1 = df_pct_air_bag.loc[:,["Injured",'restraint_used','air_bag_deployed']]
df_ml3_b = pd.get_dummies(columns=['restraint_binary',"air_bag","Manner_collision"], data =df_ml3 )
df_ml3_check = df_ml3_b.copy()
cor1 = df_ml3_check.corr()
cor1[cor1 != 1].stack().nlargest(20)[::2]
dt = tree.DecisionTreeRegressor(max_depth=2)
X = df_ml3_1.drop(columns=["Injured"])
Y = df_ml3_1.Injured
dt.fit(X,Y)
# This code will visualize a decision tree dt, trained with the attributes in X and the class labels in Y
dt_feature_names = list(X.columns)
dt_target_names = [str(s) for s in Y.unique()]
tree.export_graphviz(dt, out_file='tree.dot',
feature_names=dt_feature_names, class_names=dt_target_names,
filled=True)
graph = pydotplus.graph_from_dot_file('tree.dot')
Image(graph.create_png())
Left side of the tree (left result): Without the use of restraints and that the airbag is not deployed, the person has an expected value of 0.69. According to the lambda function of 0.5 representing injured and 1 representing death, the person is likely to be injured or death.
Right side of the tree (left result): With the use of restraints and that the airbag is not deployed, the person has an expected value of 0.245. According to the lambda function of 0 representing not injured and 0.5 representing injured, the person is unlikely to be injured.
ax=fr_df6.plot(kind='barh', title='Distribution of injury severity on restraints and air bags')
ax.set_xlabel('count')
df_restraint_notused=df_pct_air_bag[(df_pct_air_bag.restraint_binary=='Restraint not used') &\
(df_pct_air_bag.injury_severity=="Death")].groupby('state_name')['injury_severity'].\
value_counts().unstack().reset_index()
df_restraint_notused.sort_values(by='Death',ascending=False).head()
df_restraint_notused['state_name_abbr']=df_restraint_notused.state_name.apply(lambda x:us.states.lookup(x).abbr)
fig = px.choropleth(df_restraint_notused,
locations="state_name_abbr",
locationmode='USA-states',
color="Death",
hover_name="state_name",
scope='usa',
title='Death distribution due to lack of restraints across different states',
width=800,
height=400,
color_continuous_scale=px.colors.sequential.Tealgrn)
fig.show()
df_state_Death=df_pct_air_bag[(df_pct_air_bag.restraint_binary=='Restraint not used') &\
(df_pct_air_bag.injury_severity=="Death")].\
groupby(['state_name','latitude','longitude'])\
['injury_severity'].value_counts().unstack().reset_index()
highest_state_injury=df_restraint_notused['Death'].sort_values(ascending=False).nlargest(3).index.to_list()
highest_3_state_injury=df_restraint_notused.iloc[[35, 4, 12],:]
highest_3_state_injury=highest_3_state_injury.state_name.to_list()
df_pct_air_bag_1=df_pct_air_bag[(df_pct_air_bag.restraint_binary=='Restraint not used') &\
(df_pct_air_bag.injury_severity=="Death")]
df_pct_air_bag_1=df_pct_air_bag_1[df_pct_air_bag_1.apply(lambda x : \
x['state_name'] in highest_3_state_injury, axis=1)]
lat_mean=df_pct_air_bag_1.latitude.mean()
long_mean=df_pct_air_bag_1.longitude.mean()
px.set_mapbox_access_token ='pk.eyJ1IjoieW9nYXIiLCJhIjoiY2tpNGMzZjF3MTZocTJ0bnp2am83bm00ZCJ9.wzkHbz3AU14X1sfpgXE6oA'
fig = px.scatter_mapbox(data_frame=df_pct_air_bag_1,
lat="latitude",
lon="longitude",
color="injury_severity",
color_continuous_scale=px.colors.cyclical.Edge_r,
)
fig.update_layout(mapbox_style="carto-positron",\
mapbox_zoom=5, mapbox_center = {"lat": lat_mean, "lon": long_mean})